package com.uenpay.im.ui.old.activity.publicnumber;

import com.uenpay.im.configuration.APIConfiguration;
import com.uenpay.im.entities.HttpInvokeResult;
import com.uenpay.im.invokeitems.BaseHttpInvokeItem;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.util.ArrayList;

/**
 * @author SL
 * @created 2016-1-8 上午10:27:35
 * @copyRight http://www.qiyunxin.com
 * @function 我的公众号列表
 */
public class MyPublicNumberListInvokeItem extends BaseHttpInvokeItem {
	public class MyPublicNumberListInvokeItemResult extends HttpInvokeResult {
		public ArrayList<PublicNumEntity> arrayList = new ArrayList<PublicNumEntity>();
	}

	public MyPublicNumberListInvokeItemResult getOutput() {
		return (MyPublicNumberListInvokeItemResult) GetResultObject();
	}

	public MyPublicNumberListInvokeItem(int page) {
		String url = APIConfiguration.getBaseUrl()
				+ "PublicNo/PublicNo/publicNoList?pageIndex=" + page + "&pageSize=12&"
				+ APIConfiguration.getCustIdAndToken();
		SetUrl(url);
	}

	@Override
	protected Object DeserializeResult(String responseBody) {
		MyPublicNumberListInvokeItemResult result = new MyPublicNumberListInvokeItemResult();
		JSONObject json = null;
		try {
			json = new JSONObject(responseBody);
		} catch (JSONException e) {
			e.printStackTrace();
		}
		if (json == null) {
			return null;
		}
		result.status = json.optInt("status");
		result.msg = json.optString("msg");
		if (result.status != 0) {
			return result;
		}
		JSONArray jo = json.optJSONArray("data");
		if (jo != null)
			result.arrayList = DesPublicNumEntity.desEntities(jo);
		return result;
	}
}
